package com.ponhu.ea2.goodsCenter.bms.api.controller;

import com.ponhu.ea2.common.basic.model.PagedResult;
import com.ponhu.ea2.common.basic.model.ResponseBean;
import com.ponhu.ea2.constants.CommonConstant;
import com.ponhu.ea2.query.OperationRecordLogsBaseQuery;
import com.ponhu.ea2.query.OperationRecordLogsQuery;
import com.ponhu.ea2.service.facade.OperationRecordLogsApiService;
import com.ponhu.ea2.vo.OperationRecordLogsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ponhu.ea2.constants.CommonConstant.BUSINESS_TYPE_CLOUD_TRADE;

/**
 * @author Wang
 * @date 2021/10/24 10:48 上午
 */
@RestController
@RequestMapping("/operationRecordLogs")
@Api(tags = "操作记录日志接口", value = "OperationRecordLogsController")
public class OperationRecordLogsController {

    @DubboReference(version = "1.0.0", check = false)
    private OperationRecordLogsApiService operationRecordLogsApiService;

    @ApiOperation(value = "分页查询货品操作日志")
    @PostMapping("/getInventoryLogsPage")
    public ResponseBean<PagedResult<OperationRecordLogsVO>> getInventoryLogsPage(@Validated @RequestBody OperationRecordLogsBaseQuery baseQuery) {
        OperationRecordLogsQuery operationRecordLogsQuery = new OperationRecordLogsQuery();
        BeanUtils.copyProperties(baseQuery, operationRecordLogsQuery);
        operationRecordLogsQuery.setBusinessTable(CommonConstant.BUSINESS_TYPE_INVENTORY);

        return ResponseBean.ok(operationRecordLogsApiService.getOperationRecordLogsPage(operationRecordLogsQuery));
    }

    @ApiOperation(value = "分页查询物料操作日志")
    @PostMapping("/getMaterialLogsPage")
    public ResponseBean<PagedResult<OperationRecordLogsVO>> getMaterialLogsPage(@Validated @RequestBody OperationRecordLogsBaseQuery baseQuery) {
        OperationRecordLogsQuery operationRecordLogsQuery = new OperationRecordLogsQuery();
        BeanUtils.copyProperties(baseQuery, operationRecordLogsQuery);
        operationRecordLogsQuery.setBusinessTable(CommonConstant.BUSINESS_TYPE_MASTERIAL);

        return ResponseBean.ok(operationRecordLogsApiService.getOperationRecordLogsPage(operationRecordLogsQuery));
    }

    @ApiOperation(value = "分页查询云商商品操作日志")
    @PostMapping("/getCloudTradeGoodsLogsPage")
    public ResponseBean<PagedResult<OperationRecordLogsVO>> getCloudTradeGoodsLogsPage(@Validated @RequestBody OperationRecordLogsBaseQuery baseQuery) {
        OperationRecordLogsQuery operationRecordLogsQuery = new OperationRecordLogsQuery();
        BeanUtils.copyProperties(baseQuery, operationRecordLogsQuery);
        operationRecordLogsQuery.setBusinessTable(BUSINESS_TYPE_CLOUD_TRADE);

        return ResponseBean.ok(operationRecordLogsApiService.getOperationRecordLogsPage(operationRecordLogsQuery));
    }
}
